Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solution #1396

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

solution #1396

wants to merge 2 commits into from

Conversation

VovaGld
Copy link

@VovaGld VovaGld commented Nov 12, 2024

No description provided.

Copy link

@julia4406 julia4406 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks great. In my opinion your solution is simple and correct )

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your hard work on this project! 😊 Your implementation of the caching decorator function is on the right track and meets many of the task requirements. However, there's a critical issue that needs to be addressed before we can approve the pull request. The current use of args as a dictionary key can lead to runtime errors if any of its elements are mutable. This is because mutable elements, like lists, make args unhashable, causing a TypeError. To resolve this, consider converting args to a fully hashable type or ensure that the function only accepts immutable arguments. Once this issue is fixed, your code will be much more robust and ready for approval. Keep up the great work! 🚀

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review button in the Reviewers tab.

app/main.py Outdated
storage = {}

def wrapper(*args: list) -> Any:
if args in storage:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using args directly as a dictionary key can lead to issues because args is a tuple, which is hashable, but if any of its elements are mutable (like lists), it will cause a TypeError. Consider converting args to a hashable type that only contains immutable elements, or ensure that the function only accepts immutable arguments.

app/main.py Outdated Show resolved Hide resolved
Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Great job on implementing the caching decorator function! 🎉 Your solution meets the task requirements and constraints effectively. Here are some key points and suggestions for improvement:

  1. Immutable Arguments: You've designed the decorator to work with functions that take immutable arguments, which is a crucial requirement. However, there's a critical issue with using args directly as part of the dictionary key. If any elements in args are mutable, it can lead to runtime errors since mutable elements make args unhashable. To fix this, consider converting args to a fully hashable type, such as a tuple, to ensure that the key is always hashable.

  2. Correct Functionality: The caching mechanism works as expected, checking if the result for given arguments is already cached and printing appropriate messages. This aligns well with the task requirements.

  3. Handling Multiple Functions: You've implemented a separate storage dictionary for each decorated function, which ensures that the cache operates correctly with multiple functions simultaneously.

  4. Code Style and Cleanliness: Your code follows good practices with descriptive variable names and consistent style. It's clean and free of unnecessary comments or print statements.

While the implementation is solid, addressing the issue with mutable arguments will make your code more robust. This decision to approve is made to help you move forward with your learning. Please review the comments and improve your code accordingly. Keep up the great work and continue to learn from these experiences! 🚀

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

storage = {}

def wrapper(*args: Any, **kwargs: Any) -> Any:
key = (args, tuple(sorted(kwargs.items())))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using args directly as part of the dictionary key can lead to runtime errors if any of its elements are mutable. Consider converting args to a fully hashable type, such as a tuple, to ensure that the key is always hashable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants